package com.atguigu.scala.chapter8


/**
 * @author lizikuan
 * @date 2021/5/25 18:23
 */
object $05_MatchClass {
  def main(args: Array[String]): Unit = {
    case class Person(val id:Int,val name:String,val age:Int){
      def this(name:String)={
        this(1002,name,20)
      }
    }
    val stu = new Student("xiaoming")
    stu match {
      case Student(x,y) => println(x,y)
    }
  }
  class Student(val name:String,val age:Int=10)
  object Student{
    def apply(name: String, age: Int): Student = new Student(name, age)
    def unapply(arg: Student): Option[(String, Int)] = {
      if(arg==null)
        None
      else
        Some((arg.name,arg.age))
    }
  }
}
